﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using H2.NET.Web.Workflow.Services;
using H2.NET.Common;
using H2.NET.Business.Core;
using H2.NET.Web.Workflow.DwzCode;
using H2.NET.Web.Management.Config.Service;
using H2.NET.Web.Management.Config.Model;

namespace H2.NET.Web.Management.Config
{
    public partial class Edit : BasePage
    {
        ConfigService _configService = new ConfigService();
        public t_smd_Config config = new t_smd_Config();

        protected void Page_Load(object sender, EventArgs e)
        {
            string _action = AksRequest.GetQueryString("action");

            if (string.IsNullOrEmpty(_action))
            {
                GetConfigInfo();
                return;
            }
            else 
            {
                UpdateConfigInfo();
            }
        }

        #region 获取实体信息=================================
        private void GetConfigInfo()
        {

            int pId = AksRequest.GetQueryInt("pId");
            hd_parentId.Value = pId.ToString();
            rel.Value = Request["rel"];
            
            int id = AksRequest.GetQueryInt("id");
            if (id == 0)
            {
                ErrorMsg("传输参数不正确！");
                return;
            }

            this.config = _configService.GetModel(id);
        }
        #endregion

        #region 更新实体信息================================
        private void UpdateConfigInfo()
        {
            string hd = Request["hd_parentId"];
            t_smd_Config _config = new t_smd_Config();
            _config.ConfigID = AksRequest.GetFormInt("id");
            _config.Name = AksRequest.GetFormString("name");
            _config.Value = AksRequest.GetFormString("value");
            _config.Seq = AksRequest.GetFormInt("order_xh");
            _config.Code = AksRequest.GetFormString("code");
            if (hd != null && !hd.Equals("0") && !hd.Equals(""))
            {
                _config.ParentID = int.Parse(hd);
            }
            _configService.Update(_config);

            string rel = Request["rel"];
            if (rel != null && !rel.Equals("0") && !rel.Equals(""))
            {
                SuccessMsg("ConfigIndex_" + rel);
            }
            else
            {
                SuccessMsg("ConfigIndex");
            }
            return;
        }
        #endregion
    }
}